package com.hyacinth.infrastructure.db;

import java.io.Serializable;

import javax.persistence.EntityManager;

import com.hyacinth.common.constant.ThreadLocals;

public abstract class DaoSupport implements IPersistable,Serializable {
	
	private static final long serialVersionUID = 1826413809773684800L;

	public EntityManager manager() {
		return ThreadLocals.ENTITY_MANAGER.get();
	}

	public void persist() {
		manager().persist(this);
	}

	public boolean exists() {
		return (this.getId()!=null) && (manager().find(this.getClass(), this.getId())!=null);
	}

	public void refresh() {
		manager().refresh(this);
	}

	public void remove() {
		manager().remove(this);
	}

	public void meger() {
		manager().merge(this);
	}
}
